package edu.hcnu.controller;


import edu.hcnu.domain.UserDTO;
import edu.hcnu.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @description:
 * @author: Administrator
 * @time: 2022/12/21 22:20
 */

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("login")
    public Map<String,Object> login( @RequestParam String username,@RequestParam String password) {
        UserDTO userDTO = new UserDTO(username, password);
        log.info("前端提交DTO {}", userDTO);
        Map<String, Object> login = userService.login(userDTO);
        if (login != null) {
            log.info("登录成功{}", userDTO);
            return login;
        } else {
            log.error("登录失败 {}", userDTO);
            return null;
        }
    }

    @GetMapping("logout")
    public String logout() {
        boolean logout = userService.logout();
        if (logout) {
            return "下线成功";
        } else {
            return "下线失败";

        }
    }



}
